<template>
  <div class="page_padding board_year">
    <MyNavBar @goback="goback" :title="title" />
    <div class="board_year_content" :class="{ 'is-save': $route.query.isEnd !== 'true' }">
      <YearSummary
        ref="yearSum"
        :disabled="$route.query.isEnd == 'true' ? true : false"
        :info="formData"
        @subMit="submmitData" />
      <!-- 底部 -->
      <div class="fead_boot" v-if="$route.query.isEnd !== 'true'">
        <div class="btn_li" @click="commitBoard('0')">暂存</div>
        <div class="btn_li" @click="commitBoard('1')">提交</div>
      </div>
    </div>
  </div>
</template>

<script>
import MyNavBar from '@com/MyNavBar'
import YearSummary from './components/YearSummary.vue'
import { getYearRecordForm, saveYearRecordForm } from '@api/api-documentary.js'
export default {
  components: {
    MyNavBar,
    YearSummary,
  },
  data() {
    return {
      routerQuery: {},
      formData: {},
      title: '',
    }
  },
  created() {},
  mounted() {
    this.routerQuery = this.$route.query
    this.title = `${this.$route.query.year}年度个人总结`
    this.getYearInit()
  },
  methods: {
    // 返回
    goback() {
      this.$router.go(-1)
    },
    removeHtmlStyle(html) {
      const rel = /style\s*?=\s*?([‘"])[\s\S]*?\1/g
      let newHtml = ''
      if (html) {
        newHtml = html.replace(rel, '')
      }
      return newHtml
    },

    // 提交
    commitBoard(saveStatus) {
      this.$refs.yearSum.addSum(String(saveStatus))
    },
    getYearInit() {
      getYearRecordForm({
        id: this.routerQuery.noteId,
      })
        .then(res => {
          this.formData = res.data
        })
        .catch(() => {})
    },
    submmitData(data) {
      this.formData = data
      if (data.saveStatus === '0') {
        this.$toast.success('暂存成功')
      } else if (data.saveStatus === '1') {
        this.$toast.success('提交成功')
        this.$router.go(-1)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.board_year {
  font-size: 14px;
  .is-save {
    padding-bottom: 60px;
  }
}
</style>
